package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.WebLinkTypeDAO;
import com.swlz.entity.WebLinkType;
import com.swlz.exception.CodeException;
import com.swlz.service.WebLinkTypeService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 网站链接类别
 * ClassName : com.swlz.service.impl.WebLinkTypeServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-22 14:50:43
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class WebLinkTypeServiceImpl implements WebLinkTypeService {
	
	private WebLinkTypeDAO webLinkTypeDAO = new WebLinkTypeDAO();

	@Override
	public int add(WebLinkType webLinkType) throws CodeException {
		try {
			return webLinkTypeDAO.insertSelective(webLinkType);
		} catch (SQLException e) {
			throw new CodeException(500, "添加网站链接类别错误",e);
		}
	}

	@Override
	public int update(WebLinkType webLinkType) throws CodeException {
		try {
			return webLinkTypeDAO.updateSelective(webLinkType);
		} catch (SQLException e) {
			throw new CodeException(501, "修改网站链接类别错误",e);
		}
	}

	@Override
	public int delete(Long linkTypeId) throws CodeException {
		try {
			return webLinkTypeDAO.deleteById(linkTypeId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除网站链接类别错误",e);
		}
	}

	@Override
	public WebLinkType get(Long linkTypeId) throws CodeException {
		try {
			return webLinkTypeDAO.selectById(linkTypeId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取网站链接类别失败",e);
		}
	}

	@Override
	public PageVO<WebLinkType> page(WebLinkType webLinkType, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = webLinkTypeDAO.countByModel(webLinkType);
			PageVO<WebLinkType> page = new PageVO<>(total, current, rowMax);
			return page.setList(webLinkTypeDAO.selectByModel(webLinkType, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取网站链接类别分页数据失败",e);
		}
	}


}
